package com.gin.no_gay_alliance.listener;

import android.view.View;

/**
 * 请求按钮的点击事件
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/8/20 23:07
 **/
public abstract class RequestButtonOnClickListener implements View.OnClickListener {
    private boolean loading;

    @Override
    public final void onClick(View view) {
        if (loading) {
            onLoading(view);
            return;
        }
        loading = true;
        load(view);
    }

    /**
     * 执行请求
     *
     * @param view view
     */
    protected abstract void load(View view);

    /**
     * 当正在请求被点击时执行的操作 如：报错提示
     *
     * @param view view
     */
    public void onLoading(View view) {

    }

    /**
     * 请求完毕时调用
     *
     * @param view view
     */
    public final void finish(View view) {
        loading = false;
        onFinish(view);
    }

    /**
     * 执行finish方法之后的回调
     *
     * @param view view
     */
    protected void onFinish(View view) {

    }
}
